# -*- coding: utf-8 -*-
# @Time : 2021/2/3 上午 12:24
# @Author : lijunlong
# @Email : 729619494@qq.com
# @File : test_clientsearch_ture.py
# @Project : test0

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from tools.tootls import Tools
from time import sleep

class AddClientPage(BasePage,Tools):
    """定义添加客户页面"""
    url_ = "http://192.168.1.14/crm/index.php?m=customer&a=add"
    clientname_locator = (By.ID,"name")
    save_locator = (By.TAG_NAME, "input[value=保存]")
    industry_locator = (By.ID,"industry")
    nature_locator = (By.NAME,"ownership")
    revenue_locator = (By.ID,"annual_revenue")
    origin_locator = (By.ID, "origin")
    post_locator = (By.ID, "zip_code")
    score_locator = (By.NAME,"rating")
    contator_locator = (By.NAME,"con_name")
    con_phone_locator = (By.NAME,"con_telephone")


    def clientname(self,clientname):
        self.findE(self.clientname_locator).send_keys(clientname)

    def saveclient(self):
        self.findE(self.save_locator).click()

    def nature_select(self,text):
        lines = self.findEs(self.nature_locator)
        for i in range(len(lines)):
            line = lines[i].get_attribute("value")
            if text in line:
                lines[i].click()

    def score_select(self,text):
        lines = self.findEs(self.score_locator)
        for i in range(len(lines)):
            line = lines[i].get_attribute("value")
            if text in line:
                lines[i].click()


    def creat_client(self,industry_name="电子商务",nature="合资",revenue="1-10万",origin="电话营销",
                     clientname="心平气和公司",post="610000",start="一星",contator_name="王一水",con_phone="18280137077"):
        """
        这是一个创建客户的函数！一键创建客户帮你节省大量的时间！
        """
        self.selector(industry_name,self.industry_locator)
        self.nature_select(nature)
        self.selector(revenue, self.revenue_locator)
        self.selector(origin, self.origin_locator)
        self.findE(self.post_locator).send_keys(post)
        self.score_select(start)
        self.findE(self.contator_locator).send_keys(contator_name)
        self.findE(self.con_phone_locator).send_keys(con_phone)
        self.clientname(clientname)
        self.saveclient()
        # try:
        #     self.findE(close_locator).click()
        # except Exception:










